/*
 * Copyright 2009 Eat Local Food, LLC
 * Copyright (c) 2007 osCommerce (this file was written after
 * code review of osCommerce).
 *
 * This file is part of gwtCommerce.
 *
 * gwtCommerce is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * gwtCommerce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gwtCommerce.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.elf.gwt.common.client.model;

import com.google.gwt.json.client.JSONObject;

/**
 *  
 */
public class AddressModel extends AbstractModel
{
	protected boolean defaultAddress;
	protected int id;
	protected String gender;
	protected String company;
	protected String name; //used during checkout only.
	protected String firstname;
	protected String lastname;
	protected String street;
	protected String suburb;
	protected String postcode;
	protected String city;
	protected String state;
	protected String country;
	
	public AddressModel()
	{
		update();
	}
	
	public void update()
	{
		defaultAddress = false;
		id = 0;
		gender = "";
		company = "";
		firstname = "";
		lastname = "";
		street = "";
		suburb = "";
		postcode = "";
		city = "";
		state = "";
		country = "";
	}

	public AddressModel(JSONObject jsonObject)
	{
		defaultAddress = convertToBoolean(jsonObject, "default");
		id = convertToInteger(jsonObject, "id");
		gender = convertToString(jsonObject, "gender");
		company = convertToString(jsonObject, "company");
		firstname = convertToString(jsonObject, "firstname");
		lastname = convertToString(jsonObject, "lastname");
		street = convertToString(jsonObject, "street_address");
		suburb = convertToString(jsonObject, "suburb");
		postcode = convertToString(jsonObject, "postcode");
		city = convertToString(jsonObject, "city");
		state = convertToString(jsonObject, "state");
		country = convertToString(jsonObject, "country");
	}

	public void update(AddressModel model)
	{
		defaultAddress = model.isDefaultAddress();
		id = model.getId();
		gender = model.getGender();
		company = model.getCompany();
		firstname = model.getFirstname();
		lastname = model.getLastname();
		street = model.getStreet();
		suburb = model.getSuburb();
		postcode = model.getPostcode();
		city = model.getCity();
		state = model.getState();
		country = model.getCountry();
	}

	public String getCity() {
		return city;
	}

	public String getCompany() {
		return company;
	}

	public String getCountry() {
		return country;
	}

	public String getFirstname() {
		return firstname;
	}

	public String getGender() {
		return gender;
	}

	public int getId() {
		return id;
	}

	public String getLastname() {
		return lastname;
	}

	public String getPostcode() {
		return postcode;
	}

	public String getState() {
		return state;
	}

	public String getStreet() {
		return street;
	}

	public String getSuburb() {
		return suburb;
	}

	public boolean isDefaultAddress() {
		return defaultAddress;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public void setDefaultAddress(boolean defaultAddress) {
		this.defaultAddress = defaultAddress;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public void setPostcode(String postcode) {
		this.postcode = postcode;
	}

	public void setState(String state) {
		this.state = state;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public void setSuburb(String suburb) {
		this.suburb = suburb;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
